package com.project.controller;


import com.project.bean.RepliesBean;
import com.project.bean.UserBean;
import com.project.service.IUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private IUserService userService;


    @RequestMapping("login")
    public String login(String name , String pwd, HttpServletRequest request){
        UserBean user = userService.login(name, pwd);
        if (user == null){
            return "no";
        }
        request.getSession().setAttribute("loginUser",user);
        return "ok";
    }

    @RequestMapping("getLoginUser")
    public UserBean getLoginUser(HttpServletRequest request){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        return user;
    }

    @RequestMapping("add")
    public String add(UserBean user){
         userService.add(user);
         return "ok";
    }

    @RequestMapping("findByName")
    public UserBean findByName(String name){
        return userService.findByName(name);
    }

    @RequestMapping("findById")
    public String findById(int id){
        userService.findById(id);
        return "ok";
    }

}
